package sol.leetcode;

import java.util.Arrays;

/**
 * Counting Bits
 */
public class Issue338 {
    public int[] countBits(int num) {
        int n = 2;
        int bits[] = new int[num + 1];
        while (n <= num * 2) {
            for (int i = n / 2; i < Math.min(n, num + 1); ++i)
                bits[i] = bits[i - n / 2] + 1;
            n *= 2;
        }
        return bits;
    }

    public static void main(String[] args) {
        int nums = 5;
        int[] bits = new Issue338().countBits(nums);
        System.out.println(Arrays.toString(bits));
    }
}
